package com.cdc.dimen;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

import com.cdc.dp.MLog;
import com.cdc.dp.ScreenAdaptation;
import com.cdc.dp.StatusBarUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity{


    String [] pres=new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(pres,1);
        }

        StatusBarUtil.setColor(this,0x88ffffff,150);
        //StatusBarUtil.setDarkMode(this);







        MLog.Config config=new MLog.Config();
        config.setLogConsoleSwitch(true);
        config.setDir(Environment.getExternalStorageDirectory()+"/tempABC");
        Log.e("file",config.getDir());
        MLog.setConfig(config);

    }

    /**
     * 计算状态栏颜色
     *
     * @param color color值
     * @param alpha alpha值
     * @return 最终的状态栏颜色
     */
    private  int calculateStatusColor(@ColorInt int color, int alpha) {
        if (alpha == 0) {
            return color;
        }
        float a = 1 - alpha / 255f;
        int red = color >> 16 & 0xff;
        int green = color >> 8 & 0xff;
        int blue = color & 0xff;
        red = (int) (red * a + 0.5);
        green = (int) (green * a + 0.5);
        blue = (int) (blue * a + 0.5);
        return 0xff << 24 | red << 16 | green << 8 | blue;
    }

  /*  {
        "density":"3.375",
            "dpi":"540",
            "heightPixels":"1920",
            "widthPixels":"1080",
            "scaledDensity":"3.375",
            "xdpi":"397.565",
            "ydpi":"399.737",
            "xdp":"320.0",
            "ydp":"568.8889",
            "os":"7.1.1",
            "brand":"samsung",
            "model":"SM-A7100",
            "versionName":"1.0.1",
            "versionCode":"2",
            "baseDpi":"320dp"
    }*/

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1 && resultCode== Activity.RESULT_OK){

        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 1) {
            for (int i = 0; i < permissions.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {//选择了“始终允许”
                    //Toast.makeText(this, "" + "权限" + permissions[i] + "申请成功", Toast.LENGTH_SHORT).show();
                    String  screenAndModel=ScreenAdaptation.getScreenAndModel();
                    MLog.file("abc",screenAndModel);
                }
            }

        }
    }
}